package com.acwebsitedesign.uRateDrugs.domain;

import org.springframework.validation.Errors;



public class DrugValidator {
	
	 @SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
	        return Account.class.equals(clazz);
	    }

	    public void validate(Object object, Errors e) {
	        Drug drug = (Drug) object;
	        String name = drug.getName();
	        String classOfDrug = drug.getClassOfDrug();
	        String whyIsThisMedicationPrescribed = drug.getWhyIsThisMedicationPrescribed();
	        String otherBrands = drug.getOtherBrands();
	        String sideEffects = drug.getSideEffects();
	        String warnings = drug.getWarnings();
	        String treats = drug.getTreats();

	        if (name == null || "".equals(name)) {
	        	e.rejectValue("name", "drugName.empty");
	        }
	        else if (classOfDrug == null || "".equals(classOfDrug)){
	        	e.rejectValue("classOfDrug", "classOfDrug.empty");}
	       
	        	else if (whyIsThisMedicationPrescribed == null || "".equals(whyIsThisMedicationPrescribed)){
		       e.rejectValue("whyIsThisMedicationPrescribed", "whyIsThisMedicationPrescribed.empty");}
		   
		       else if (otherBrands == null || "".equals(otherBrands)){
		     e.rejectValue("otherBrands", "otherBrands.empty");}
		  
		     else if (sideEffects == null || "".equals(sideEffects)){
			  e.rejectValue("sideEffects", "sideEffects.empty");   }  
			
			  else if (warnings == null || "".equals(warnings)){
				e.rejectValue("warnings", "warnings.empty");}
	        
			  else if (treats == null || "".equals(treats)){
					e.rejectValue("treats", "treats.empty");}
	    }
}
